﻿using FirstTry.DB;
using FirstTry.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FirstTry.CTR
{
   public class BatteryCtr
    {
        private DBBattery dbb = new DBBattery();
        private DBTest dbt = new DBTest();
        
        

        public BatteryCtr()
        {

        } 
        
        public Battery getBattery(string ID)
        {
            Battery b = new Battery();
            b = dbb.getBattery(ID);
            return b;
        }

        public List<Battery> getAllBattery()
        {
            return dbb.getAllBattery();
        }

        public void addBattery(Location l, bool booked, bool charged)
        {
            Battery b = new Battery();
            b.location = l;
            b.booked = booked;
            b.charged = charged;

            dbb.addBattery(b);
        }

        public void editBattery(Battery b)
        {
            dbb.editBattery(b);
        }

        public void deleteBattery(Battery b)
        {
            dbb.deleteBattery(b);
        }

        public List<Battery> getBatteryByLocation(string locationID)
        {
            return dbb.getBatteryByLocation(locationID);
        }

        public bool checkBatteryByLocation(int y, int x)
        {
            ReservationCtr rctr = new ReservationCtr();
            LocationCtr lctr = new LocationCtr();
            bool r;
            Location l = lctr.getLocationByCoordinates(y, x);
            List<Battery> lb = rctr.checkBatteryByLocation(l);
            if (lb.Count > 0)
            {
                r = true;
            }
            else
            {
                r = false;
            }

            return r;

        }

    }
}
